package com.zxl.designpattern.behavioral.state;

/**
 * 具体状态类：支付状态（也可以叫待支付状态，这里仅作示例，不分那么清了）
 */
public class PayingState implements State {

    // 贩卖机
    private final VendingMachine vendingMachine;
    
    /**
     * 构造函数，初始化贩卖机引用
     * @param vendingMachine 贩卖机对象
     */
    public PayingState(VendingMachine vendingMachine) {
        this.vendingMachine = vendingMachine;
    }
    
    @Override
    public void pay(int amount) {
        // 模拟调用支付接口并获取返回值
        System.out.println("成功支付 " + amount + " 元");
        // 状态修改为已发货
        vendingMachine.setState(vendingMachine.getSoldState());
    }
    
    @Override
    public void selectItem() {
        System.out.println("您已经选择了商品，请支付 " + vendingMachine.getPrice() + " 元");
    }
    
    @Override
    public void dispense() {
        System.out.println("请先支付");
    }
    
    @Override
    public void refill(int quantity) {
        System.out.println("商品未售罄");
    }
}    